
package samples;
// {{{ imports
import jp.ize.ux.UXRoot;
import jp.ize.ux.UXObject;
import jp.ize.ux.events.UXMouseEvent;
import jp.ize.ux.geom.UXRect;
import jp.ize.ux.geom.UXSize;
import jp.ize.ux.components.UXEllipseBox;
import jp.ize.ux.components.UXImage;
import jp.ize.ux.acts.Act;
import jp.ize.ux.acts.EllipseAct;
import jp.ize.ux.acts.VisibilityAct;
import jp.ize.ux.tween.easings.Expo;

import jp.ize.iwp.RuntimeEngine;
import jp.ize.iwp.utils.DebugUtil;
// }}}
// {{{ class EllipseBox3
class EllipseBox3
{
	// {{{ public static function main()

	public static function main()
	{
		RuntimeEngine.init();
		DebugUtil.init();
		DebugUtil.setLocation( 300, 500 );
		var ellipseb = new UXEllipseBox(300,150,0,180);
		var a = new EllipseAct();
		var v = new VisibilityAct();

		// ActionインタラクションをMouseDown で起こすことにする。
		ellipseb.alpha = 0.2;
		ellipseb.ctrl.getInteraction("Action").addReactEvent(UXMouseEvent.DOWN);
		var func:EllipseStateType->WipeParameter = function(state) {
			var idx:Int = 0;
			for ( i in 0...state.children.length ) {
				if ( state.children[i]==state.eventTarget ) {
					idx = i;
				}
			}
			var actparam:WipeParameter = {
				time:0.3,
				transition:Expo.easeOut,
				center:idx
			};
			return actparam;
		}
		ellipseb.ctrl.getInteraction("Action").addAct(a.wipe(null,func));

		// InitインタラクションをMouseOverのときに起こすことにし、その動作は0.3秒でlayoutすることにする。
		var actparam1:FadeParameter = {
			time:0.3,
			transition:Expo.easeOut,
			dir:VisibilityActDir.SHOW
		};
 		ellipseb.ctrl.getInteraction("Init").addReactEvent(UXMouseEvent.OVER);
 		ellipseb.ctrl.getInteraction("Init").addAct(v.fade(actparam1));
		var actparam3:ActParameter = {
			time:0.3,
			transition:Expo.easeOut
		};
 		ellipseb.ctrl.getInteraction("Init").addAct(a.layout(actparam3));

		ellipseb.x = 400;
		ellipseb.y = 500;
		ellipseb.addUXChild(new UXImage("Pref.png"));
		ellipseb.addUXChild(new UXImage("lambda-icon.png", new UXSize(100,100)));
		ellipseb.addUXChild(new UXImage("Safari.png"));
		ellipseb.addUXChild(new UXImage("ImageCapture.png"));
		ellipseb.addUXChild(new UXImage("TimeMachine.png"));
		ellipseb.addUXChild(new UXImage("iPhoto.png"));
		ellipseb.addUXChild(new UXImage("iTunes.png"));
		ellipseb.addUXChild(new UXImage("mail.png"));
		ellipseb.addUXChild(new UXImage("robot.png"));		
		UXRoot.addUXChild(ellipseb);
		
		// {{{ wipe action
		// 最初のレイアウト終了後は、wipeインタラクションと整列インタラクションを
		// 交互に発生させるようにします。
		var flag:Bool = true;
		ellipseb.ctrl.getInteraction("Action").addFinishHandler(
			function(state) {
				ellipseb.ctrl.getInteraction("Action").clearActs();
				if ( flag ) {
					var actparam1:ActParameter = {
						time:0.3,
						transition:Expo.easeOut,
					};
					ellipseb.ctrl.getInteraction("Action").addAct(a.layout(actparam1));
					flag = false;
				} else {
					var func:EllipseStateType->WipeParameter = function(state) {
						var idx:Int = 0;
						for ( i in 0...state.children.length ) {
							if ( state.children[i]==state.eventTarget ) {
								idx = i;
							}
						}
						var actparam:WipeParameter = {
							time:0.3,
							transition:Expo.easeOut,
							center:idx
						};
						return actparam;
					}
					ellipseb.ctrl.getInteraction("Action").addAct(a.wipe(null,func));
					flag = true;
				}
			}
		);
		// }}}
	}

	// }}}
}
// }}}
